<template>
  <div>
    <a-modal title='发货地址(可通过双击行选择)' :width='1000' :dialog-style="{ top: '10px' }" :visible='visible' :confirmLoading='loading' :footer='null' @cancel='handleCancel'>
      <f-search-form :more='false' @searchHandler='searchHandler' style='margin-bottom: 5px'>
        <f-search-form-item label='地址' name='address' style='width: 350px' />
      </f-search-form>
      <f-table ref='table' rowKey='customAddressId' :scroll='{x:true}' :dialog-style="{ top: '10px' }" v-if='visible' @dblclick='dblclick' :tableColumns='columns' :multiple='false' :showRadio='true' :operator='operator' :params='queryParam' :api='api.customAddress' handler='customAddressSelectPageListHandler' @onSelectChange='onSelectChange'>
        <span slot='action' slot-scope='text, record'>
              <template>
                <a @click='edit(record)'>编辑</a>
              </template>
            </span>
      </f-table>
    </a-modal>
    <custom-address-modal ref='customAddressModal'></custom-address-modal>
  </div>
</template>
<script>
import api from "../custom/js/api"
import CustomAddressModal from "@/views/module/business/custom/custom_address_modal"

export default {
  name: "SelectCustomAddressModal",
  props: {},
  data() {
    let operator = []
    operator.push({
      name: "同步收货地址",
      that: this,
      icon: "sync",
      handler: (table, that) => {
        this.http.confirm(this, {
          content: "确认同步数据吗?",
          url: api.custom.syncCustomAddress,
          data: {
            customCode: this.queryParam.customCode
          },
          success: (me, data) => {
            this.$refs.table.refresh()
          }
        })
      }
    })
    operator.push({
      name: "刷新",

      that: this,
      handler: (table, that) => {
        this.$refs.table.refresh(false)
      }
    })
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      loading: false,
      visible: false,
      selectedRowKeys: [],
      selectedRows: [],
      //列表初始化查询参数
      queryParam: {},
      formItem: {
        amount: 0
      },
      // 表头
      columns: [
        {
          title: "收货地址",
          align: "left",
          width: "360px",
          dataIndex: "address"
        },
        {
          title: "联系人",
          align: "center",
          width: "100px",
          dataIndex: "userName"
        },
        {
          title: "联系电话",
          align: "center",
          width: "100px",
          dataIndex: "telephone"
        },
        {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "70px",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  methods: {
    open(params) {
      this.queryParam = params
      this.visible = true
      this.selectedRowKeys = []
      this.selectedRows = []
    },
    edit(record) {
      this.$refs["customAddressModal"].showModal(record)
    },
    close() {
      this.$emit("close")
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    dblclick(record, event) {
      let selectedRowKeys = []
      let selectedRows = []
      selectedRowKeys.push(record.customAddressId)
      selectedRows.push(record)
      this.$emit("onSelectChange", selectedRowKeys, selectedRows)
      this.close()
    },
    //商品选择回调
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    }
  },
  created() {
  },
  components: { CustomAddressModal }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
